package com.jinxin.platform.cddjnhjcxtsysset.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomeExpend;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomePrice;
import com.jinxin.platform.cddjnhjcxtsysset.common.SysOrgInfo;
import com.jinxin.platform.cddjnhjcxtsysset.common.SysUserVO;
import com.jinxin.platform.cddjnhjcxtsysset.rpc.CddjnhjcxtsyssetRpc;
import com.jinxin.platform.cddjnhjcxtsysset.service.ICddjnhjcxtsyssetHomeExpendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2020-12-26
 * @Author: Lingnan
 **/
@APCOSApi(value = "首页支出相关接口", developers = {"lingnan"}, description = "首页支出相关接口")
@Api(tags = "首页支出相关接口")
@RestController
@RequestMapping("/cddjnhjcxtsysset/cddjnhjcxtsyssetHomeExpend")
@Slf4j
public class CddjnhjcxtsyssetHomeExpendController {
    @Autowired
    private ICddjnhjcxtsyssetHomeExpendService homeExpendService;
    @Autowired
    private CddjnhjcxtsyssetRpc cddjnhjcxtsyssetRpc;

    @APCOSApiOperation(value = "根据条件查询首页支出信息", developers = {"lingnan"}, description = "根据条件查询首页支出信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @ApiOperation(value = "根据条件查询首页支出信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="type",value="支出类型", paramType="query",dataType="String")
    })
    @GetMapping("/list")
    public JsonResult list(@RequestParam(required = false) String type){
        SysUserVO currentUser = cddjnhjcxtsyssetRpc.getCurrentUser();
        if(currentUser == null){
            return JsonResult.error("获取当前用户信息失败");
        }
        HashMap param = new HashMap();
        param.put("type", type);
        param.put("orgId", currentUser.getOrgId());
        List<CddjnhjcxtsyssetHomeExpend> list = homeExpendService.list(param);
        return JsonResult.ok("success",list);
    }

    @APCOSApiOperation(value = "保存支出信息", developers = {"lingnan"}, description = "保存支出信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody List<CddjnhjcxtsyssetHomeExpend> records){
        return homeExpendService.saveOrUpdate(records);
    }

    @APCOSApiOperation(value = "导入费用支出", developers = {"lingnan"}, description = "导入费用支出",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/import")
    public JsonResult importData(@RequestParam(value = "file") MultipartFile file,
                                 @RequestParam(value = "titleConfig") String titleMap){
        return homeExpendService.importExcel(file,titleMap);
    }

    @APCOSApiOperation(value = "导出费用支出", developers = {"lingnan"}, description = "导出费用支出",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @ApiOperation(value = "导出学生信息")
    @GetMapping("/export2Excel")
    public void export2Excel(HttpServletResponse response){
        homeExpendService.export2Excel(response);
    }

}
